'use strict';
const BaseController = require('./base');
const jwt = require('jsonwebtoken');
const {Op} = require("sequelize");
class RouterController extends BaseController {
  constructor(ctx) {
    super(ctx, 'user');
  }
  getListQuery(query) {
    let where = {}
    if (query.keyword) {
      // 手机号、姓名搜索
      where = {
        [Op.or]: [
          { nickname: { [Op.like]: `%${query.keyword}%` } },
          { phone: { [Op.like]: `%${query.keyword}%` } }
        ]
      }
    }
    return where
  }
  async wxLogin() {
    const { ctx } = this;
    const { request, service } = ctx;
    const data = request.body;
    const user = await service.user.wxLogin(data);
    user.token = jwt.sign(user, this.config.keys);
    ctx.success(user);
  }
}
module.exports = RouterController;
